package org.ss.psci.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.ss.psci.entity.PmBuyPlan;

/**
 * Data access object (DAO) for domain model class PmBuyPlan.
 * 
 * @see org.ss.psci.entity.PmBuyPlan
 * @author MyEclipse Persistence Tools
 */

public class PmBuyPlanDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(PmBuyPlanDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String SEQ = "seq";
	public static final String NUM = "num";
	public static final String PER_PRICE = "perPrice";
	public static final String TOTAL_PRICE = "totalPrice";
	public static final String REMARK = "remark";
	public static final String PROPOSER = "proposer";
	public static final String COMPANY = "company";
	public static final String MANAGER = "manager";

	protected void initDao() {
		// do nothing
	}

	public void save(PmBuyPlan transientInstance) {
		log.debug("saving PmBuyPlan instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(PmBuyPlan persistentInstance) {
		log.debug("deleting PmBuyPlan instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public PmBuyPlan findById(java.lang.Integer id) {
		log.debug("getting PmBuyPlan instance with id: " + id);
		try {
			PmBuyPlan instance = (PmBuyPlan) getHibernateTemplate().get(
					"org.ss.psci.entity.PmBuyPlan", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(PmBuyPlan instance) {
		log.debug("finding PmBuyPlan instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding PmBuyPlan instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from PmBuyPlan as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findBySeq(Object seq) {
		return findByProperty(SEQ, seq);
	}

	public List findByNum(Object num) {
		return findByProperty(NUM, num);
	}

	public List findByPerPrice(Object perPrice) {
		return findByProperty(PER_PRICE, perPrice);
	}

	public List findByTotalPrice(Object totalPrice) {
		return findByProperty(TOTAL_PRICE, totalPrice);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findByProposer(Object proposer) {
		return findByProperty(PROPOSER, proposer);
	}

	public List findByCompany(Object company) {
		return findByProperty(COMPANY, company);
	}

	public List findByManager(Object manager) {
		return findByProperty(MANAGER, manager);
	}

	public List findAll() {
		log.debug("finding all PmBuyPlan instances");
		try {
			String queryString = "from PmBuyPlan";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public PmBuyPlan merge(PmBuyPlan detachedInstance) {
		log.debug("merging PmBuyPlan instance");
		try {
			PmBuyPlan result = (PmBuyPlan) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(PmBuyPlan instance) {
		log.debug("attaching dirty PmBuyPlan instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(PmBuyPlan instance) {
		log.debug("attaching clean PmBuyPlan instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static PmBuyPlanDAO getFromApplicationContext(ApplicationContext ctx) {
		return (PmBuyPlanDAO) ctx.getBean("PmBuyPlanDAO");
	}
}